<? $params = preg_split('/,/', PARAMS); ?>
<div id="languagebar">
    <span><?=uygulama::translate('Current language')?>: <?=LOCALE?> | <?=LANG?></span>
    <?if(MULTILINGUAL):?>
    <select onchange="changeLang(this)">
        <?foreach (uygulama::languages() as $k=>$i):?>
        <option value="<?=$k?>"<?=$k==LANG?'selected="selected"':''?>><?=$i?></option>
        <?endforeach;?>
    </select>
    <?endif;?>
</div>
<div id="navadmin">
    <?if(ACCESS>=3):?>
    <a href="/admin/options" class="link<?=$params[0]=='default'||$params[0]=='options'?' selected':''?>"><?=uygulama::translate('Project Options')?></a>
    <a href="/admin/seo" class="link<?=$params[0]=='seo'?' selected':''?>"><?=uygulama::translate('SEO')?></a>
    <a href="/admin/languages" class="link<?=$params[0]=='languages'?' selected':''?>"><?=uygulama::translate('Language Settings')?></a>
    <a href="/admin/themes" class="link<?=$params[0]=='themes'?' selected':''?>"><?=uygulama::translate('Themes')?></a>
    <a href="/admin/templates" class="link<?=$params[0]=='templates'?' selected':''?>"><?=uygulama::translate('Page Templates')?></a>
    <a href="/admin/info" class="link<?=$params[0]=='info'?' selected':''?>"><?=uygulama::translate('Project Info')?></a>
    <?endif;?>
    <?if(ACCESS>=1):?>
    <a href="/admin/pages" class="link<?=$params[0]=='pages'||$params[0]=='page'?' selected':''?>"><?=uygulama::translate('Pages')?></a>
    <a href="/admin/logout" class="link<?=$params[0]=='logout'?' selected':''?>"><?=uygulama::translate('Logout')?></a>
    <?endif;?>
    <a title="uygulama :: http://uygulama.net" href="http://uygulama.net" target="_blank">
        <img id="uygulama" src="/templates/admin/images/logo.png" alt="uygulama" />
    </a>
    <a id="projectlink" title="<?=DOMAIN?>" href="http://<?=DOMAIN?>" target="_blank">
        <?=uygulama::translate('View Project');?>
    </a>
</div>
<script type="text/javascript">
    function changeLang(el){
        tool.post({'url':'/json/<?=TEMPLATE?>/language','data':'lang='+$(el).val(),'onComplete':function(){ location.href = location.href;}});
    }
</script>
<?if(!ACCESS):?>
<h3><?=uygulama::translate('Admin Panel')?></h3>
<form id="form" class="login" method="POST" action="/json/<?=TEMPLATE?>/login">
    <div class="formItem">
        <label><?=uygulama::translate('Username')?>:</label> <input id="username" name="username" type="text" />
        <div class="clear"></div>
    </div>
    <div class="formItem">
        <label><?=uygulama::translate('Password')?>:</label> <input id="password" name="password" type="password" />
        <div class="clear"></div>
    </div>
    <div class="formSubmit">
        <span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
        <input type="submit" value="<?=uygulama::translate('Login')?>" />
    </div>
</form>
<script>$(document).ready(function() {tool.form(); $('username').focus(); });</script>
<?else:
// CHECK
if(!is_writable('data/config.php')){?>
<div id="content">
    <h3><?=uygulama::translate('Setup')?></h3>
    <h2><?=uygulama::translate('Error: <u>data/</u> folder is not writable. Please set <u>data/</u> folder writing permission.')?></h2>
</div>
<? } else switch ($params[0]):
// OPTIONS =====================================================================
default:
case 'options':?>
<div id="content">
    <form id="form" method="POST" action="/json/<?=TEMPLATE?>/options">
        <h3><?=uygulama::translate('Project Admin')?></h3>
        <div class="formItem">
            <label><?=uygulama::translate('Username')?>:</label> <input id="admin" name="admin" type="text" value="<?=ADMIN?>" />
            <span class="desc"><?=uygulama::translate('Admin username')?></span>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Password')?>:</label> <input id="apassword" name="apassword" type="password"/>
            <span class="desc"><?=uygulama::translate('Admin password')?></span>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Confirm password')?>:</label> <input id="arepassword" name="arepassword" type="password"/>
            <span class="clear"></span>
        </div>
        <h3><?=uygulama::translate('Project Editor')?></h3>
        <div class="formItem">
            <label><?=uygulama::translate('Editorial')?>:</label>
            <a class="checkboxItem" title="editorial" onclick="editorialpanel(this)"><span class="check"><span>&nbsp;</span></span></a>
            <input id="editorial" name="editorial" type="hidden" value="<?=EDITORIAL?>" />
            <span class="desc"><?=uygulama::translate('Do you want to create an editor account? Editors only have access to page editing.')?></span>
        </div>
        <div id="editorialpanel" <?=EDITORIAL?'':'style="display:none'?>">
             <div class="formItem">
                <label><?=uygulama::translate('Username')?>:</label> <input id="editor" name="editor" type="text" value="<?=EDITOR?>" />
                <span class="desc"><?=uygulama::translate('Editor username')?></span>
            </div>
            <div class="formItem">
                <label><?=uygulama::translate('Password')?>:</label> <input id="epassword" name="epassword" type="password"/>
                <span class="desc"><?=uygulama::translate('Editor password')?></span>
            </div>
            <div class="formItem">
                <label><?=uygulama::translate('Confirm password')?>:</label> <input id="erepassword" name="erepassword" type="password"/>
                <span class="clear"></span>
            </div>
        </div>
        <h3><?=uygulama::translate('Project Settings')?></h3>
        <div class="formItem">
            <label><?=uygulama::translate('Domain name')?>:</label> <input id="domain" name="domain" type="text" value="<?=DOMAIN?>" />
            <span class="desc"><?=uygulama::translate('[eg: example.com]')?></span>
        </div>
        <div class="formItem">
            <label class="formLabel"><?=uygulama::translate('Logo')?>:</label>
            <div class="uploader">
                <object id="logoUploader" type="application/x-shockwave-flash" data="/lib/f4/uploader.swf" width="80" height="26">
                    <param name="movie" value="/lib/f4/uploader.swf" />
                    <param name="quality" value="high" />
                    <param name="wmode" value="window" />
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="flashVars" value="callback=logoUploader
                           &uploadurl=/upload/<?=TOKEN?>/logo
                           &filetypes=*.png;
                           &typetext=Logo (.png;)
                           &labeltext=<?=uygulama::translate('Browse')?>
                           &fontcolor=#ffffff
                           &bgcolor=0x111111
                           &autoupload=1"/>
                </object>
                <span class="uploaderLabel"><?=uygulama::translate('Select a new logo image')?></span>
                <span id="logoprogress" class="progress"></span>
                <script type="text/javascript">
                    logoUploader = function(a, m){
                        switch(a){
                            case 'ioerror':
                            case 'securityerror':
                                tool.result(600, m.type, m.text);
                                break;
                            case 'progress':
                                $('#logoprogress').css('width',(m.bytesLoaded / m.bytesTotal *100 >> 0)+'%');
                                break;
                            case 'complete':
                                m = eval('(' + m + ')')
                                if(m.code == 200) $('#prelogo').attr('src','/logo.png?'+Math.random());
                                else tool.result(m.code,m.status,m.message,m.fields,m.redirect,m.debug);
                                break;
                        }
                    }
                </script>
            </div>
            <span class="desc"><img id="prelogo" src="/logo.png" alt="logo" /></span>
        </div>
        <div class="formItem">
            <label class="formLabel"><?=uygulama::translate('Favicon')?>:</label>
            <div class="uploader">
                <object id="myUploader" type="application/x-shockwave-flash" data="/lib/f4/uploader.swf" width="80" height="26">
                    <param name="movie" value="/lib/f4/uploader.swf" />
                    <param name="quality" value="high" />
                    <param name="wmode" value="window" />
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="flashVars" value="callback=faviconUploader
                           &uploadurl=/upload/<?=TOKEN?>/favicon
                           &filetypes=*.ico;
                           &typetext=Favicon (.ico;)
                           &labeltext=<?=uygulama::translate('Browse')?>
                           &fontcolor=#ffffff
                           &bgcolor=0x111111
                           &autoupload=1"/>
                </object>
                <span class="uploaderLabel"><?=uygulama::translate('Select a new favicon')?></span>
                <span id="faviconprogress" class="progress"></span>
                <script type="text/javascript">
                    faviconUploader = function(a, m){
                        switch(a){
                            case 'ioerror':
                            case 'securityerror':
                                tool.result(600, m.type, m.text);
                                break;
                            case 'progress':
                                $('#faviconprogress').css('width',(m.bytesLoaded / m.bytesTotal *100 >> 0)+'%');
                                break;
                            case 'complete':
                                m = eval('(' + m + ')')
                                if(m.code == 200) $('#favicon').attr('src','/favicon.ico?'+Math.random());
                                else tool.result(m.code,m.status,m.message,m.fields,m.redirect,m.debug);
                                break;
                        }
                    }
                </script>
            </div>
            <span class="desc"><img id="favicon" src="/favicon.ico" alt="favicon" /></span>
        </div>

        <div class="formSubmit">
            <span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
            <input type="submit" value="<?=uygulama::translate('Save')?>" />
        </div>
    </form>
</div>
<div id="aside"></div>
<script type="text/javascript">
    $(document).ready(function() { tool.form(1); });
    function editorialpanel(el){
        if(!$(el).hasClass('checked')){
            $('#editorialpanel').css('display','block');
        } else {
            $('#editorialpanel').css('display','none');
        }
    }
</script>
<?break;
// LANGUAGES ===================================================================
case 'languages':?>
<div id="content">
    <h3><?=uygulama::translate('Languages')?></h3>
    <form id="form" method="POST" action="/json/<?=TEMPLATE?>/languages">
        <div class="formItem">
            <label><?=uygulama::translate('Multilingual')?>:</label>  <select id="multilingual" name="multilingual">
                <option value="0"<?=!MULTILINGUAL?'selected="selected"':''?>><?=uygulama::translate('No')?></option>
                <option value="1"<?=MULTILINGUAL?'selected="selected"':''?>><?=uygulama::translate('Yes')?></option>
            </select>
            <span class="desc"><?=uygulama::translate('Is the project multilingual?')?></span>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Default language')?>:</label> <select id="defaultlang" name="defaultlang">
                <?foreach (uygulama::languages() as $k=>$i):?>
                <option value="<?=$k?>"<?=$k==DEFLANG?'selected="selected"':''?>><?=$i?></option>
                <?endforeach;?>
            </select>
            <span class="desc"><?=uygulama::translate('If the client browser does not support selected languages, the project will be displayed in default language.')?></span>
        </div>
        <div>
            <h3><?=uygulama::translate('Supported languages')?>:</h3>
            <div>
                <?foreach (uygulama::languages(true) as $k=>$i):
                $checked = ($k==DEFLANG||strstr(SUPPORTEDLANGS, $k))?'checked="checked"':''; ?>
                <span class="checkbox"><input id="<?=$k?>" name="supportedlangs[]" type="checkbox" value="<?=$k?>" title="<?=$i?>" onchange="deflangs(this)" <?=$checked?> />
                                              <label for="<?=$k?>">[<?=$k?>] <?=$i?></label></span>
                <?endforeach;?>
                <span class="clear"></span>
            </div>
            <span class="desc"><?=uygulama::translate('Check the languages you wish to write in.')?></span>
        </div>
        <div class="formSubmit">
            <span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
            <input type="submit" value="<?=uygulama::translate('Save')?>" />
        </div>
    </form>
</div>
<div id="aside">
    <div class="adminmenu">
        <a class="button selected" href="/admin/languages"><?=uygulama::translate('Languages')?></a>
        <a class="button" href="/admin/translations"><?=uygulama::translate('Translations')?></a>
    </div>
</div>
<script type="text/javascript">
    var _complete = function(){ location.href =location.href; };
    $(document).ready(function() { tool.form(1,0,1); });
    var deflangs = function(el){
        if(el.checked){
            console.log('checked',$('#defaultlang'));
            $('#defaultlang').append('<option value="'+$(el).val()+'">'+$(el).attr('title')+'</option>');
        } else {
            console.log('unchecked',$('#defaultlang'));
            $('#defaultlang option[value='+el.value+']').remove();
        }
    }
</script>
<?break;
// TRANSLARIONS ================================================================
case 'translations':
$params[1] = $params[1] ? $params[1] : 'lib';
$params[2] = $params[2] ? $params[2] : 'uygulama';
?>
<div id="content">
    <h3><?=uygulama::translate('Translations')?></h3>
    <script type="text/javascript">
        function dictionary(d){
            location.href = "/admin/translations,"+d;
        }
    </script>
    <div class="formItem">
        <label><?=uygulama::translate('Dictionaries')?>:</label><select id="template" name="dictionary" onchange="dictionary($(this).val())">
            <?foreach (uygulama::dictionaries() as $k=>$i):?>
            <option value="<?=$i?>"<?=$i==$params[1].','.$params[2]?'selected="selected"':''?>><?=$k?></option>
            <?endforeach;?>
        </select>
        <span class="desc"><?=uygulama::translate('Select a template or a library dictionary')?></span>
    </div>
    <h3><?=sprintf(uygulama::translate('Dictionary of %s'), $params[1].', '.$params[2])?></h3>
    <form id="form" method="POST" action="/json/<?=TEMPLATE?>/translations">
        <?
        if(($gettext = uygulama::gettext($params[1], $params[2]))) foreach($gettext as $key=>$word): ?>
        <div class="formItem">
            <label class="translation"><?=$word->def?></label>
            <textarea name="word[<?=$key?>]" class="translation"><?=$word->$lang?></textarea>
            <span class="clear"></span>
        </div>
        <? endforeach; ?>
        <div class="formSubmit">
            <span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
            <input name="type" type="hidden" value="<?=$params[1]?>" />
            <input name="part" type="hidden" value="<?=$params[2]?>" />
            <input type="submit" value="<?=uygulama::translate('Save')?>" />
        </div>
    </form>
    <script>$(document).ready(function() { tool.form(); });</script>
</div>
<div id="aside">
    <div class="adminmenu">
        <a class="button" href="/admin/languages"><?=uygulama::translate('Languages')?></a>
        <a class="button selected" href="/admin/translations"><?=uygulama::translate('Translations')?></a>
    </div>
</div>
<?break;
// THEMES ======================================================================
case 'themes':?>
<div id="content">
    <h3 class="top"><?=uygulama::translate('Themes')?></h3>
    <?foreach (uygulama::themes() as $i):?>
    <div class="theme">
        <img src="/themes/<?=$i?>/thumb.png" alt="<?=$i?>" class="theme" />
        <span><?=$i?></span>
        <a class="button" href="/<?=$i?>.thm" target="_blank"><?=uygulama::translate('Preview')?></a>
        <a class="button theme" rel="<?=$i?>"><?=uygulama::translate('Apply')?></a>
        <a class="button" href="http://<?=DOMAIN?>/themes/<?=$i?>.zip"><?=uygulama::translate('Download')?></a>
    </div>
    <?endforeach;?>
    <script type="text/javascript">
        $('a.theme').bind('click',function(e){
            var item = $(this);
            tool.post({'url':'/json/<?=TEMPLATE?>/theme','data':'page=<?=$params[1]?>&theme='+item.attr('rel'),'onComplete':function(r){
                    if(r.code == 200) {
                        $('#selected').empty();
                        var theme = $('<div>').addClass('theme').appendTo($('#selected'));
                        $('<img>').attr({'class':'theme','src':item.parent().find('img').attr('src')}).appendTo(theme);
                        $('<span>').html(item.parent().find('span').html()).appendTo(theme);
                        $('#selected').hide().fadeIn();
                    } else tool.result(r.code,r.status,r.message,r.fields,r.redirect,r.debug);
                }
            });
        });
    </script>
</div>
<div id="aside">
    <h3 class="top"><?=uygulama::translate('Current Theme')?></h3>
    <div id="selected">
        <div class="theme">
            <img class="theme" src="/themes/<?=THEME?>/thumb.png" alt="active theme" >
            <span><?=THEME?></span>
        </div>
    </div>
    <br>
    <h3><?=uygulama::translate('Upload New Theme')?></h3>
    <div class="formItem">
        <label class="formLabel" style="width:50px;"><?=uygulama::translate('Theme')?>:</label>
        <div class="uploader">
            <object id="themeUploader" type="application/x-shockwave-flash" data="/lib/f4/uploader.swf" width="80" height="26">
                <param name="movie" value="/lib/f4/uploader.swf" />
                <param name="quality" value="high" />
                <param name="wmode" value="window" />
                <param name="allowScriptAccess" value="sameDomain" />
                <param name="flashVars" value="callback=themeUploader
                       &uploadurl=/upload/<?=TOKEN?>/<?=$params[0]?>,<?=$params[1]?>,theme
                       &filetypes=*.zip;
                       &typetext=Theme (.zip;)
                       &labeltext=<?=uygulama::translate('Browse')?>
                       &fontcolor=#ffffff
                       &bgcolor=0x111111
                       &autoupload=1"/>
            </object>
            <span class="uploaderLabel"><?=uygulama::translate('Select a theme')?></span>
            <span id="themeprogress" class="progress"></span>
            <script type="text/javascript">
                themeUploader = function(a, m){
                    switch(a){
                        case 'ioerror':
                        case 'securityerror':
                            tool.result(600, m.type, m.text);
                            break;
                        case 'progress':
                            $('themeprogress').css('width',(m.bytesLoaded / m.bytesTotal *100 >> 0)+'%');
                            break;
                        case 'complete':
                            m = eval('(' + m + ')')
                            if(m.code == 200) location.href = location.href;
                            else tool.result(m.code,m.status,m.message,m.fields,m.redirect,m.debug);
                            break;
                    }
                }
            </script>
        </div>
        <div class="clear"></div>
    </div>
</div>
<?break;
// TEMPLATES ===================================================================
case 'templates':?>
<div id="content">
    <h3 class="top"><?=uygulama::translate('Page Templates')?></h3>
    <?foreach (uygulama::templates() as $i):?>
    <div class="template">
        <img src="/templates/<?=$i?>/thumb.png" alt="<?=$i?>" class="template" />
        <span><?=$i?></span>
        <a class="button" href="http://<?=COOKIELESS?>/templates/<?=$i?>.zip"><?=uygulama::translate('Download')?></a>
    </div>
    <?endforeach;?>
</div>
<div id="aside">
    <?if(TEMPLATEUPLOAD):?>
    <h3 class="top"><?=uygulama::translate('Upload New Page Template')?></h3>
    <div class="formItem">
        <label class="formLabel" style="width:55px;"><?=uygulama::translate('Template')?>:</label>
        <div class="uploader">
            <object id="templateUploader" type="application/x-shockwave-flash" data="/lib/f4/uploader.swf" width="80" height="26">
                <param name="movie" value="/lib/f4/uploader.swf" />
                <param name="quality" value="high" />
                <param name="wmode" value="window" />
                <param name="allowScriptAccess" value="sameDomain" />
                <param name="flashVars" value="callback=templateUploader
                       &uploadurl=/upload/<?=TOKEN?>/<?=$params[0]?>,<?=$params[1]?>,template,
                       &filetypes=*.zip;
                       &typetext=Page template (.zip;)
                       &labeltext=<?=uygulama::translate('Browse')?>
                       &fontcolor=#ffffff
                       &bgcolor=0x111111
                       &autoupload=1"/>
            </object>
            <span class="uploaderLabel"><?=uygulama::translate('Select a page template')?></span>
            <span id="templateprogress" class="progress"></span>
            <script type="text/javascript">
                templateUploader = function(a, m){
                    switch(a){
                        case 'ioerror':
                        case 'securityerror':
                            tool.result(600, m.type, m.text);
                            break;
                        case 'progress':
                            $('templateprogress').css('width',(m.bytesLoaded / m.bytesTotal *100 >> 0)+'%');
                            break;
                        case 'complete':
                            m = eval('(' + m + ')')
                            if(m.code == 200) location.href = location.href;
                            else tool.result(m.code,m.status,m.message,m.fields,m.redirect,m.debug);
                            break;
                    }
                }
            </script>
        </div>
        <div class="clear"></div>
    </div>
    <? endif; ?>
</div>
<?break;
// INFO ========================================================================
case 'info':?>
<div id="content">
    <h3><?=uygulama::translate('Info')?></h3>
    <form id="form" method="POST" action="/json/<?=TEMPLATE?>/info">
        <div class="formItem">
            <label><?=uygulama::translate('Title')?>:</label> <input id="title" name="title" type="text" class="wide" value="<?=$page->title->$lang?>" />
            <div class="clear"></div>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Description')?>:</label> <input id="description" name="description" class="wide" type="text" value="<?=$page->description->$lang?>" />
            <div class="clear"></div>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Keywords')?>:</label> <input id="keywords" name="keywords" class="wide" type="text" value="<?=$page->keywords->$lang?>" />
            <div class="clear"></div>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Copyright')?>:</label> <input id="copyright" name="copyright" class="wide" type="text" value="<?=$page->copyright->$lang?>" />
            <div class="clear"></div>
        </div>
        <div class="formSubmit">
            <span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
            <input type="submit" value="<?=uygulama::translate('Save')?>" />
        </div>
    </form>
    <script>$(document).ready(function() { tool.form(); });</script>
</div>
<div id="aside"></div>
<?break;
// PAGES =======================================================================
case 'pages':?>
<div id="content">
    <h3 class="top"><?=uygulama::translate('Pages')?></h3>
    <form id="form" method="POST" action="/json/<?=TEMPLATE?>/pages,set">
        <div id="pages">
            <? if($page->navigator->pages): foreach ($page->navigator->pages as $page=>$name): $lang = LANG; ?>
            <div id="<?=$page?>" class="formItem">
                <span class="handler">::</span>
                <input name="name[<?=$page?>]" type="text" value="<?=$name->$lang?>" />
                <input class="disabled link" type="text" value="<?=$page?>" disabled="disabled" />
                <a class="button" href="/admin/page,<?=$page?>"><?=uygulama::translate('Edit')?></a>
                <?if(ACCESS >= 3):?><a class="button" href="javascript:del('<?=$page?>');"><?=uygulama::translate('Delete')?></a><?endif;?>
                <a id="def<?=$page?>" class="select<?=$page==DEFPAGE?' selected':''?>" href="javascript:def('<?=$page?>');"><?=$page==DEFPAGE ? uygulama::translate('Main Page') : uygulama::translate('Set as Main Page')?></a>
                <div class="clear"></div>
            </div>
            <? endforeach; else: ?>
            <div id="nopage" class="formItem formMesssage"><?=uygulama::translate('Any pages have created yet')?></div>
            <? endif; ?>
        </div>
        <div class="formSubmit">
            <span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
            <input type="submit" value="<?=uygulama::translate('Save')?>" />
        </div>
    </form>
</div>
<div id="aside">
    <?if(ACCESS >= 3):?>
    <h3 class="top"><?=uygulama::translate('New Page')?></h3>
    <div id="addPage">
        <div class="formItem">
            <label><?=uygulama::translate('Link')?></label>
            <input id="url" name="url" type="text" value="" />
            <a id="urlpost" href="javascript:post();" class="button">[+] <?=uygulama::translate('Add')?></a>
            <div class="clear"></div>
        </div>
        <script>$(document).ready(function() { tool.form(); });</script>
    </div>
    <?endif;?>
    <h3><?=uygulama::translate('Backup')?></h3>
    <div id="backup">
        <a class="button" href="/data.zip"><?=uygulama::translate('Click here to backup the data/ folder')?></a>
    </div>
</div>
<script>
    var linksort;function 
    add(url){
        if($('#nopage'))$('#nopage').remove();
        var item = $('<div>',{'id':url,'class':'formItem'});
        $('<span>',{'class':'handler','text':'::'}).appendTo(item);
        $('<input>',{'name':'name['+url+']','type':'text'}).appendTo(item);
        $('<input>',{'class':'disabled','type':'text','value':url,'disabled':'disabled'}).appendTo(item);
        $('<a>',{'class':'button','href':'/admin/page,'+url})
        .html("<?=uygulama::translate('Edit')?>").appendTo(item);
        $('<a>',{'class':'button','href':'javascript:del(\''+url+'\')'})
        .html("<?=uygulama::translate('Delete')?>").appendTo(item);
        $('<a>',{'id':'def'+url,'class':'select','href':'javascript:def(\''+url+'\')'})
        .html("<?=uygulama::translate('Set as Main Page')?>").appendTo(item);
        $('<div>',{'class':'clear'}).appendTo(item);
        //linksort.addItems(item);
        item.appendTo('#pages');
    }
    function def(url){
        tool.post({'url':'/json/<?=TEMPLATE?>/defpage','data':'defaultpage='+url,'onComplete':function(r){
                if(r.code == 200) { 
                    $('a.select').html("<?=uygulama::translate('Set as Main Page')?>").removeClass('selected');
                    $('#def'+url).html("<?=uygulama::translate('Main Page')?>").addClass('selected');
                } else tool.result(r.code,r.status,r.message,r.fields,r.redirect,r.debug);
            }
        });
    }
    function del(url){
        var func = 'tool.post({\'url\':\'/json/<?=TEMPLATE?>/pages,del\',\'data\':\'url='+url+'\',\'onComplete\':function(r){'
            +'if(r.code == 200) $(\'#'+url+'\').remove(); '
            +'else tool.result(r.code,r.status,r.message,r.fields,r.redirect,r.debug);'
            +'}'
            +'});';
        tool.confirm("<?=uygulama::translate('Delete Page')?>", "<?=uygulama::translate('Are you sure to delete the page? You will lose all data!')?>", func);
    }
    function post(){
        $('#urlpost').attr('disabled','disabled');
        var val = $('#url').val().toLowerCase();
        tool.post({'url':'/json/<?=TEMPLATE?>/pages,add','data':'url='+val,'onComplete':function(r){
                if(r.code == 200) add(val);
                else tool.result(r.code,r.status,r.message,r.fields,r.redirect,r.debug);
                $('#urlpost').removeAttr('disabled');
            }
        });
    }
    $(document).ready(function() { 
        linksort = tool.sortable('pages','span',{'url':'/json/<?=TEMPLATE?>/pages,sort'});
        $('#url').keydown(function(e){
            if((e.keyCode == 13) && $('#url').val() && $('#url').val() != $('#url').attr('data-value')) { // enter
                if(e) e.preventDefault();
                post();
            } else {
                var c = e.keyCode;
                if((c >= 35 && c <= 39) ||(c >= 48 && c <= 57) || (c >= 65 && c <= 90)
                    || c == 8
                    || c == 46
                    || c == 189
                    || c == 190) return true;
                console.log(e.keyCode);
                return false;
            }
        }); 
    });
</script>
<?break;
// PAGE ========================================================================
case 'page':?>
<?if($page->page->template):?>
<h3>
    <a href="/admin/pages"><?=uygulama::translate('Pages')?></a> >
    <?=uygulama::translate('Page Edit')?> :: '<?=$params[1]?>' | <?=uygulama::translate('Template')?> :: '<?=$page->page->template?>'</h3>
<? include 'templates/'.$page->page->template.'/admin.html'; ?>
<?else:?>
<div id="content">
    <h3><?=uygulama::translate('Choose Page Template')?></h3>
    <?foreach (uygulama::templates() as $i):?>
    <div class="template">
        <img src="/templates/<?=$i?>/thumb.png" alt="<?=$i?>" class="template" />
        <span><?=$i?></span>
        <?/*<a href="/<?=$i?>.thm" target="_blank"><?=uygulama::translate('Preview')?></a>*/?>
        <a class="button template" rel="<?=$i?>"><?=uygulama::translate('Choose')?></a>
    </div>
    <?endforeach;?>
    <script>
        $('a.template').click(function(e){
            var item = $(this);
            $('#selected').empty().append($('<div>',{'class':'template'})
            .append($('<img>',{'class':'template','src':item.parent().find('img').attr('src')})));
            $('<a>',{'class':'button','href':'/admin/page,<?=$params[1]?>'})
            .html("<?=uygulama::translate('Apply Template >')?>")
            .click(function(e){
                tool.post({'url':'/json/<?=TEMPLATE?>/template','data':'page=<?=$params[1]?>&template='
                        +item.attr('rel'),'onComplete':function(r){
                        if(r.code == 200) {
                            location.href = location.href;
                        } else tool.result(r.code,r.status,r.message,r.fields,r.redirect,r.debug);
                    }});
            }).appendTo($('#selected'));
        });
    </script>
</div>
<div id="aside">
    <h3><?=uygulama::translate('Page Template')?></h3>
    <div id="selected"></div>
    <?=uygulama::translate('To chage the template after applied, the page must be deleted and recreated entirely.')?>
</div>
<?endif;?>
<?break;
// SEO =========================================================================
case 'seo':?>
<div id="content">
    <form id="form" method="POST" action="/json/<?=TEMPLATE?>/options">
        <h3><?=uygulama::translate('AJAX / Lower Bandwidth')?></h3>
        <div class="formItem">
            <label><?=uygulama::translate('AJAX')?>:</label>
            <a class="checkboxItem" title="ajax"><span class="check"><span>&nbsp;</span></span></a>
            <input id="ajax" name="ajax" type="hidden" value="<?=AJAX?>" />
            <span class="desc"><?=uygulama::translate('If AJAX mode is activated, system work with XHTTP request.')?></span>
        </div>
        <h3><?=uygulama::translate('Developemet Mode / Compress Data')?></h3>
        <div class="formItem">
            <label><?=uygulama::translate('Development')?>:</label>
            <a class="checkboxItem" title="development"><span class="check"><span>&nbsp;</span></span></a>
            <input id="development" name="development" type="hidden" value="<?=DEVELOPMENT?>" />
            <span class="desc"><?=uygulama::translate('If development mode is activated, system does not compress js, css, html files.')?></span>
        </div>
        <h3><?=uygulama::translate('Search Engine Optimization')?></h3>
        <div class="formItem">
            <label>Cookieless:</label> <input id="cookieless" class="wide" name="cookieless" type="text" value="<?=COOKIELESS?>" />
            <span class="desc"><a href="http://cookieless.org/" target="_blank">http://cookieless.org</a> <?=uygulama::translate('[ex: uygulama.cookieless.org]')?></span>
        </div>
        <div class="formItem">
            <label>Analytics:</label> <input id="analytics" class="wide" name="analytics" type="text" value="<?=ANALYTICS?>" />
            <span class="desc"><a href="http://www.google.com/analytics/" target="_blank"><?=uygulama::translate('Google Analytics Code')?></a> <?=uygulama::translate('[ex: #UA-012346]')?></span>
        </div>
        <div class="formItem">
            <label>Alexa:</label> <input id="alexa" class="wide" name="alexa" type="text" value="<?=ALEXA?>" />
            <span class="desc"><a href="http://www.alexa.com/siteowners" target="_blank">http://www.alexa.com/siteowners</a></span>
        </div>
        <div class="formItem">
            <label>Webmaster:</label> <input id="webmaster" class="wide" name="webmaster" type="text" value="<?=WEBMASTER?>" />
            <span class="desc"><a href="http://www.google.com/webmasters/" target="_blank">http://www.google.com/webmasters/</a></span>
        </div>
        <div class="formItem">
            <label>Siteexplorer:</label> <input id="siteexplorer" class="wide" name="siteexplorer" type="text" value="<?=SITEEXPLORER?>" />
            <span class="desc"><a href="http://siteexplorer.search.yahoo.com/" target="_blank">http://siteexplorer.search.yahoo.com/</a></span>
        </div>
        <div class="formItem">
            <label>robots.txt:</label> <textarea id="robots" class="wide" name="robots"><?=$page->robots?></textarea>
            <span class="desc"><a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449&from=35237&rd=1" target="_blank">robots.txt</a></span>
        </div>
        <div class="formItem">
            <label>humans.txt:</label> <textarea id="humans" class="wide" name="humans"><?=$page->humans?></textarea>
            <span class="desc"><a href="http://humanstxt.org/" target="_blank">humans.txt</a></span>
        </div>
        <h3><?=uygulama::translate('GEO TAGS')?></h3>
        <div class="formItem">
            <label><?=uygulama::translate('Place Name')?>:</label> <input id="geoplacename" class="wide" name="geoplacename" type="text" value="<?=GEOPLACENAME?>" />
            <span class="desc"></span>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('GEO Region')?>:</label> <input id="georegion" name="georegion" type="text" value="<?=GEOREGION?>" />
            <span class="desc"><?=uygulama::translate('[ex: TR-22]')?></span>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Latitude')?>:</label> <input id="geolatitude" name="geolatitude" type="text" value="<?=GEOLATITUDE?>" />
            <span class="desc"></span>
        </div>
        <div class="formItem">
            <label><?=uygulama::translate('Longitude')?>:</label> <input id="geolongitude" name="geolongitude" type="text" value="<?=GEOLONGITUDE?>" />
            <span class="desc"><a href="http://en.wikipedia.org/wiki/Geotagging" target="_blank">http://en.wikipedia.org/wiki/Geotagging</a></span>
        </div>
        <div class="formSubmit">
            <span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
            <input type="submit" value="<?=uygulama::translate('Save')?>" />
        </div>
    </form>
    <h3><?=uygulama::translate('Site Maps')?></h3>
    <div class="formItem">
        <label><?=uygulama::translate('Sitemap')?>:</label><a class="formLink" href="http://<?=DOMAIN?>/sitemap.xml" target="_blank">http://<?=DOMAIN?>/sitemap.xml</a>
        <span class="desc"><?=uygulama::translate('Project sitemap url')?></span>
    </div>
    <div class="formItem">
        <label><?=uygulama::translate('Sitemap index')?>:</label><a class="formLink" href="http://<?=DOMAIN?>/sitemapindex.xml" target="_blank">http://<?=DOMAIN?>/sitemapindex.xml</a>
        <span class="desc"><?=uygulama::translate('Project sitemap index url for subpages')?></span>
    </div>
    <div class="formItem">
        <label><?=uygulama::translate('Sitemap ping')?>:</label>
        <a class="formLink" href="http://www.google.com/webmasters/tools/ping?sitemap=http://<?=DOMAIN?>/sitemap.xml" target="_blank"><?=uygulama::translate('Google sitemap ping')?></a>
        <a class="formLink" href="http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=http://<?=DOMAIN?>/sitemap.xml" target="_blank"><?=uygulama::translate('Yahoo sitemap ping')?></a>
        <a class="formLink" href="http://webmaster.live.com/webmaster/ping.aspx?siteMap=http://<?=DOMAIN?>/sitemap.xml" target="_blank"><?=uygulama::translate('Bing sitemap ping')?></a>
        <a class="formLink" href="http://www.google.com/webmasters/tools/ping?sitemap=http://<?=DOMAIN?>/sitemapindex.xml" target="_blank"><?=uygulama::translate('Google sitemap index ping')?></a>
        <a class="formLink" href="http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=http://<?=DOMAIN?>/sitemapindex.xml" target="_blank"><?=uygulama::translate('Yahoo sitemap index ping')?></a>
        <a class="formLink" href="http://webmaster.live.com/webmaster/ping.aspx?siteMap=http://<?=DOMAIN?>/sitemapindex.xml" target="_blank"><?=uygulama::translate('Bing sitemap index ping')?></a>
        <span class="desc"><?=uygulama::translate('Search Engine\'s sitemap ping links')?></span>
    </div>
</div>
<div id="aside"></div>
<script>
    $(document).ready(function() { tool.form(1); });
    function developmentmode(el){
        if(el.checked){
            $('development').set('value',1);
        } else {
            $('development').set('value',0);
        }
    }
</script>
<?break;?>
<?endswitch;?>
<?endif;?>